package com.laamella.syntherface.synths.models;

import javax.sound.midi.InvalidMidiDataException;

import com.laamella.syntherface.synths.midi.Bits;
import com.laamella.syntherface.synths.midi.MidiInterface;

/**
 * A parameter model that automatically sends value changes to the synth as an
 * NRPN value.
 */
@SuppressWarnings("serial") public class NrpnParameterModel extends ParameterModelWithMidiInterface {

	private final int parameterNumber;

	public NrpnParameterModel(String name, int initialValue, MidiInterface midiInterface, int parameterNumber, ParameterType type) {
		super(name, initialValue, midiInterface, type);
		this.parameterNumber = parameterNumber;
	}

	public NrpnParameterModel(String name, MidiInterface midiInterface, int parameterNumber) {
		this(name, 0, midiInterface, parameterNumber, ParameterType.OnOff);
	}
	public NrpnParameterModel(String name, MidiInterface midiInterface, int parameterNumber, ParameterType type) {
		this(name, 0, midiInterface, parameterNumber, type);
	}

	public NrpnParameterModel(String name, MidiInterface midiInterface, int parameterNumber, ParameterType type, int defaultValue) {
		this(name, defaultValue, midiInterface, parameterNumber, type);
	}

	@Override public void updateSynthesizer(MidiInterface midiInterface, int value) throws InvalidMidiDataException {
		getMidiInterface().sendNrpnMessage(parameterNumber, value);
	}
	
	@Override public String getMidiDoc() {
		return "NRPN "+Bits.padWithZeroes(""+parameterNumber, 5);
	}
}
